<template>
	<view class="address-manage rf-row-wrapper">
		<view class="row b-b">
			<text class="tit">联系人</text>
			<input
				class="input"
				type="text"
				v-model="addressData.customerUserName"
				@blur="handleRealNameChange"
				placeholder="收货人姓名"
				placeholder-class="placeholder"
			/>
		</view>
		<view class="row b-b">
			<text class="tit">手机号</text>
			<input
				class="input"
				type="number"
				v-model="addressData.shippingPhone"
				@blur="handleMobileChange"
				placeholder="收货人手机号码"
				placeholder-class="placeholder"
			/>
		</view>
		<view class="row b-b" @click="aaaa()">
			<text class="tit">选择地址</text>
			<!--地址三级联动-->
			<u-picker mode="region" v-model="show" @confirm="abcd"></u-picker>
			{{addressData.selector}}
		</view>
		<view class="row b-b">
			<text class="tit">详细地址</text>
			<input
				class="input"
				type="text"
				v-model="addressData.address"
				@blur="bindAddressDetailsChange"
				placeholder="请输入详细地址"
				placeholder-class="placeholder"
			/>
		</view>
		<view class="row default-row">
			<text class="tit">设为默认</text>
			<switch
				:checked="addressData.isDefault ? 1 : 0"
				:color="themeColor.color"
				@change="switchChange"
			/>
		</view>
		<button
			class="add-btn"
			:class="'bg-' + themeColor.name"
			:disabled="btnLoading"
			:loading="btnLoading"
			@click="confirm"
		>
			提交
		</button>

		<!--加载动画-->
		<rfLoading isFullScreen :active="loading"></rfLoading>
	</view>
</template>

<script>
/**
 * @des 收货地址列表
 *
 * @author stav stavyan@qq.com
 * @date 2020-03-10 18:00
 * @copyright 2019
 */
import { addressCreate, addressUpdate, addressDetail } from '@/api/userInfo';
import rfPickRegions from '@/components/rf-pick-regions/index.vue';
export default {
	components: {
		rfPickRegions
	},
	data() {
		return {
			addressData: {
				customerUserName: '',
				shippingPhone: '',
				selector:'',
				address: '',
				isDefault: 0,
				beforeUserId:'',
				
			},
			beforeUserIdTwo:'',
			btnLoading: false,
			loading: false,
			show:false,
		};
	},
	onLoad() {
		uni.getStorage({
			key:'beforeUser',
			success: (res) => {
				this.beforeUserIdTwo=res.data.beforeUserId
			}
		})
	},
	methods: {
		aaaa(){
			  this.show = true		  
		},
		abcd(data){
			console.log(data)
			this.addressData.selector = data.province.label +"-"+ data.city.label +"-"+ data.area.label
		},
		
		// 提交
		confirm() {
			this.addressData.beforeUserId=this.beforeUserIdTwo;
			this.btnLoading = true;
			uni.request({
				url: 'http://localhost:9090/before/bgs/customer-addr/TowAddAddress', 
				data: {
					addressData: this.addressData
				},
				method: 'POST',
				success: (res) => {				
					console.log("添加成功")		
					this.btnLoading = false;
					this.$mRouter.push({
						route: `/pages/user/address/address`
					});
				}
			});
		},
	}
};
</script>

<style lang="scss">
page {
	background: $page-color-base;
}
.address-manage {
	padding-top: 16upx;
}
</style>
